/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ru.vpitervip.app.client.ui;

import ru.vpitervip.app.client.place.InformationPlace;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.AnchorElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.place.shared.Place;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

/**
 * Sample implementation of {@link PaymentView}.
 */
public class PaymentViewImpl extends Composite implements PaymentView {

	interface Binder extends UiBinder<Widget, PaymentViewImpl> {
	}
	
	private static final Binder binder = GWT.create(Binder.class);

	private Presenter listener;
	
	final DecoratedPopupPanel simplePopup = new DecoratedPopupPanel(true);

	
	@UiField
	Anchor pasportLink1;
	
	@UiField
	Anchor pasportLink2;
	
	@UiField
	Anchor infoLink;
	

	public PaymentViewImpl() {
		initWidget(binder.createAndBindUi(this));
		simplePopup.setWidget(
		        new HTML("<div style='color:black'>"+
		        		 "Пашковская Ольга Борисовна &nbsp;&nbsp  паспорт серия 4004 &nbsp  номер 888374<br></br>" +
		        		 "Каливецкая Галина Мидхатовна &nbsp;&nbsp  паспорт серия 4004 &nbsp  номер 140319"+
		        		 "</div>"));

	}

	

	@Override
	public void setPresenter(Presenter listener) {
		this.listener = listener;
		
	}
	
	
	@UiHandler("pasportLink1")
	public void onPasportLink1Click(ClickEvent event){
		
		 showPopup(event);
	
	}
	
	@UiHandler("pasportLink2")
	public void onPasportLink2Click(ClickEvent event){
		 showPopup(event);
		
	}
	
	private void showPopup(ClickEvent event){
		Widget source = (Widget) event.getSource();
        int left = source.getAbsoluteLeft() -180;
        int top = source.getAbsoluteTop() + 25;
        simplePopup.setPopupPosition(left, top);
        simplePopup.show();
	}

	@UiHandler("infoLink")
	public void onInfoLinkClick(ClickEvent event){
		 listener.goTo(new InformationPlace(""));
		
	}
}
